#!/bin/bash
SCRIPT_BASE_DIR=$( dirname "${BASH_SOURCE[0]}" )
source "${SCRIPT_BASE_DIR}/common/fs_utils.sh"

cmd=$( basename "$0" )

function usage() {
	echo "Usage: ${cmd} [ -h |-e]"
    echo -e "\t-e: 增加对外部依赖库的索引"
    echo -e "\t-h: 显示帮助信息"
	exit 1
}

# 默认不增加对外部依赖项目的索引
findExternal=false
while getopts "eh" args
do
    case "${args}" in 
        e)
            findExternal=true
            ;;
        *)
            usage;;
    esac
done

if ${findExternal}
then
    pruneOpt=""
else
    pruneOpt="-wholename */external/eigen -type d -prune -o ${pruneOpt}"
    pruneOpt="-wholename */external/emsdk -type d -prune -o ${pruneOpt}"
    pruneOpt="-wholename */external/onnx -type d -prune -o ${pruneOpt}"
    pruneOpt="-wholename */external/libprotobuf-mutator -type d -prune -o ${pruneOpt}"
    pruneOpt="-wholename */external/onnxruntime-extensions -type d -prune -o ${pruneOpt}"
fi

csFile="cscope.files"


echo "Build ${csFile} ..."
find . ${pruneOpt} -name "*.cmake" -type f -print > "${csFile}"
find . ${pruneOpt} -name CMakeLists.txt -type f -print >> "${csFile}"

echo "Build cscope DB..."
cscope -Rbqk
echo "Done."
